import request from '@/utils/request'
import { CHECC_API_BASE_DATA } from '@/constants/proxy'
import { ObjectType, ResponseDataPromise } from 'typings/interfaces'
import * as proxy from '@/constants/proxy'
import { Pagination } from '@/components/Records/types'

// 获取绿化工程列表
export function requestGreenProjectList(params: any,data): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bd-landscape-project-in/page`,
    method: 'post',
    params,
    data:data,
  })
}

// 根据id获取绿化工程列表
export function getrequestGreenProject(id: any): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bd-landscape-project-in/${id}`,
    method: 'get',
  })
}

// 保存绿化工程信息
export function saveGreenProject(data: any): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bd-landscape-project-in`,
    method: 'post',
    data
  })
}

// 删除绿化工程信息
export function delGreenProject(data: any): Promise<any> {
  const str = data.landscapeProjectInIds.reduce((rst, cur) => {
    if (rst === '?') {
      rst += `landscapeProjectInIds=${cur}`
    } else {
      rst += `&landscapeProjectInIds=${cur}`
    }
    return rst
  }, '?')
  return request({
    url: CHECC_API_BASE_DATA + `/bd-landscape-project-in/delete` + str,
    method: 'get',
    data
  })
}

// 更新绿化工程信息
export function updateGreenProject(data: any): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bd-landscape-project-in/update`,
    method: 'post',
    data
  })
}

// 锁定/解锁
export function bridgeLock(data: any): Promise<any> {
  return request({
    url: CHECC_API_BASE_DATA + `/bd-landscape-project-in/lock`,
    method: 'POST',
    data
  })
}

// 绿化工程-修建工程记录
export const fetchRecordsRequest = (
  pagination: Omit<Pagination, 'total'>,
  data: ObjectType
): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bd-landscape-project-in-construction/page',
    method: 'post',
    data,
    params: pagination,
  })

export const createRecordRequest = (data: ObjectType): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bd-landscape-project-in-construction',
    method: 'post',
    data,
  })

export const editRecordRequest = (data: ObjectType): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bd-landscape-project-in-construction',
    method: 'PUT',
    data,
  })

export const deleteRecordsRequest = (ids: string[]) =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bd-landscape-project-in-construction',
    method: 'delete',
    data: ids,
  })

export const lockRecordRequest = (id: string, lock: '0' | '1') =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bd-landscape-project-in-construction/lock',
    method: 'post',
    data: {
      id,
      lock
    },
  })


